#define _CRT SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<iostream>
using namespace std;
int row, col;
int visited[52][52] = { 0 };
char arr[52][52] = { 0 };
int x[4] = { 0,0,1,-1 };
int y[4] = { 1,-1,0,0 };
int mlen = 10000;
void Dfs(int x1,int y1,int len)
{
    visited[x1][y1] = 0;
    len++;
    if (len >= mlen)
    {
        return;
    }
    if (x1 == row - 1 && y1 == col - 1)
    {
        if (len < mlen)
            mlen = len;
    }
    for (int i = 0; i < 4; i++)
    {
        if (x1 + x[i] >= 0 && (x1 + x[i]) < row && y1 + y[i] >= 0 && y1 + y[i] < col && visited[x1 + x[i]][y1 + y[i]] == 1)
        {
            Dfs(x1 + x[i], y1 + y[i], len);
            visited[x1 + x[i]][y1 + y[i]] = 1;
        }
    }
}
int main()
{
    cin >> row >> col;
    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < col; j++)
        {
            cin >> arr[i][j];
            if (arr[i][j] == '.')
                visited[i][j] = 1;
        }
    }
    int num = 0;
    Dfs(0, 0, num);
    cout << mlen;
    return 0;
}